<template>
  <div class="AdendDialog">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="16">
          <el-form-item label="申请人" prop="user">
            <el-input v-model="ruleForm.user" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="开票主体方" prop="subjectSide">
            <el-input v-model="ruleForm.subjectSide" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="开票名称" prop="title">
            <el-input v-model="ruleForm.title" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="合同编码" prop="coding">
            <el-input v-model="ruleForm.coding" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="发票类型" prop="type">
            <el-input v-model="ruleForm.type" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="开票" prop="Invoicing">
            <el-input placeholder="请输入" v-model="ruleForm.Invoicing">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {
      close: {
        type: Function,
        default: null,
      },
      changeText: {
        type: Function,
        default: null
      },
      baobiao: {
        type: Function,
        default: null
      }
    },
    data() {
      return {
        ruleForm: {
          user: "",
          subjectSide: "",
          title: "",
          coding: "",
          type: '',
          Invoicing: '',
        },
        rules: {
          user: [{
            required: true,
            message: "请输入申请人",
            trigger: "blur",
          }, ],
          subjectSide: [{
            required: true,
            message: "请输入开票主体方",
            trigger: "blur",
          }, ],
          title: [{
            required: true,
            message: "请输入开票名称",
            trigger: "blur",
          }, ],
          coding: [{
            required: true,
            message: "请输入合同编码",
            trigger: "blur",
          }, ],
          type: [{
            required: true,
            message: "请输入发票类型",
            trigger: "blur",
          }, ],
          Invoicing: [{
            required: true,
            message: "请输入开票金额",
            trigger: "blur",
          }, ]
        }
      }
    },
    methods: {
      // 表单提交
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$server.statementsubmit(this.ruleForm).then((res) => {
              this.$message({
                type: "success",
                message: "添加成功!",
              });
              this.changeText('报表模板')
              this.baobiao()
              // 关闭弹框
              this.close();
              for (let object in this.ruleForm) {
                this.ruleForm[object] = ''
              }
            });
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.close();
      },
    }
  }
</script>

<style>
</style>
